package com.zzptc.zzj.a121huatu;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;

import java.util.ArrayList;
import java.util.List;


public class ThirdlyFragment extends Fragment {

    public ThirdlyFragment() {
        // Required empty public constructor
    }

    public static ThirdlyFragment newInstance(String param1, String param2) {
        ThirdlyFragment fragment = new ThirdlyFragment();
        Bundle args = new Bundle();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_thirdly, container, false);
        //实例化控件
        PieChart pieChart = view.findViewById(R.id.pir_cahrt);
        List<PieEntry> data=new ArrayList<>();
        //添加数据
        data.add(new PieEntry(1,"男"));
        data.add(new PieEntry(1,"女"));
        data.add(new PieEntry(1,"女"));

        PieDataSet pieDataSet=new PieDataSet(data,"女");
        //放置数据
        PieData pieData=new PieData(pieDataSet);
        pieChart.setData(pieData);

        //setColors设置多个颜色  setColor设置颜色
        pieDataSet.setColors(Color.RED,Color.BLUE,Color.CYAN);
       //设置中间圆圈颜色
       pieChart.setHoleColor(Color.YELLOW);
       //圆圈设置文本
       pieChart.setCenterText("饼图");
       //设置中间是否显示
       pieChart.setDrawHoleEnabled(false);
        return view;
    }
}
